'use strict';
(function(doc, win) {
  
  function init() {
    var $container = $('#container');
    $container.show();
    $container.find('img[data-src]').each(function () {
      this.src = this.getAttribute('data-src');
    });

    // 主划屏
    new Swiper('#container', {
      
      eventTarget: 'container',
      mousewheelControl: true,
      // initialSlide: 4,
      slideActiveClass: 'active',
      mode: 'vertical'
    });   

    

    // 客户成功案例点击展开弹出层
    var $overlay = $('#overlay');
    $('#caseList').on('click', 'li', function () {
      var name = this.getAttribute('data-name');
      $overlay.find('.popup[data-name="'+ name +'"]').show().siblings().hide();
      $overlay.show();
    });
    $overlay.on('click', '.close', function () {
      $overlay.hide();
    }); 

    
    
  }

  // 首屏图片，预加载
  var arrPreload = [
    'images/logo.png',
    'images/bg.png'
  ];

  var preload = document.getElementById('preload');
  new LoadImg(arrPreload, function(loadedCount, imgTotal) {
    loadingText.innerText = parseInt((++loadedCount / ++imgTotal) * 100) + '%';
  }, function() {
    preload.className += ' hide';
    setTimeout(function() {
      preload.style.cssText = 'display:none;';
    }, 1000);
    // todo other

    init();
  });

  // preload
  function LoadImg(images, loadend, complete) {
    var imgTotal = images.length,
      loadedCount = 0;
    var doLoad = function(url) {
      var img = new Image();
      img.onload = function() {
        ++loadedCount;
        if (typeof loadend === 'function') {
          loadend(loadedCount, imgTotal);
        }
      };
      img.src = url;
    };
    for (var i = 0; i < imgTotal; ++i) {
      doLoad(images[i]);
    }
    // show it after 60sec
    var checkTime = 60;
    var check = function() {
      if (checkTime > 0) {
        checkTime -= 0.5;
        if (loadedCount === imgTotal) {
          plushPage();
        } else {
          setTimeout(check, 500);
        }
      } else {
        if (loadedCount / imgTotal > 0.5) {
          // show it after 50%
          plushPage();
        } else {
          alert('加载图片失败，请返回刷新尝试!');
        }
      }
    };
    var plushPage = function() {
      if (typeof(complete) === 'function') {
        complete();
      }
    };
    check();
  };
})(document, window);

$(".content li img").click(function(){
  var oDiv = document.getElementById("txt");
  var timer = null;
  var str = "help.myscrm.cn"
  var num = 0 ;
  timer = setInterval(function(){
    oDiv.innerHTML += str.charAt(num);
    num++;
    if(num == str.length){
      clearInterval(timer);
      $('#click').css({top:'30%'});
      $('.btn2').css({visibility:"visible"});
    }
  },300);

})